<template>
  <div class="container">
    <div v-if="show" class="wrap">
      <div class="w-title">
        余额提现
      </div>
      <div class="content">
        <div class="item">
          <div>支付宝账号：</div>
          <div>{{account.list.account}}</div>
        </div>
        <div class="item">
          <div>支付宝姓名：</div>
          <div>{{account.list.name}}</div>
        </div>
        <div class="item">
          <div>可用余额：</div>
          <div>&nbsp;{{account.price}}&nbsp;元</div>
        </div>

        <a-form :form="form" :label-col="{ span: 7 }" :wrapper-col="{ span: 17 }" @submit="handleSubmit">
          <a-form-item label="金额（元）">
            <a-input-number id="inputNumber" style="width:100px;margin-right: 5px;" 
              :min="1"
              :max="Number(account.price)"
              :formatter="value => `${value}`"
              :parser="value => value.replace(/[^\d]/g,'')"
              v-decorator="['price', { rules: [{ required: true, message: '请确认金额' }] }]"/>
            <div class="desc">平台手续费2%</div>
            <div class="desc">最小提现金额：1元，必须是整数单位</div>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 12, offset: 7 }">
            <a-button type="primary" html-type="submit">
              提现
            </a-button>
          </a-form-item>
        </a-form>
      </div>
    </div>
    <div v-else></div >
  </div>
</template>

<script>
import { GET_REAL_NAME, CASH_MONEY } from '../server'
export default {
  layout: "main",
  components: {
  },
  data() {
    return {  
      show: false,
      money: null,
      account: {},
      form: this.$form.createForm(this, { name: 'coordinated' }),
    };
  },
  created() {
    this.getRearName()
  },
  mounted() {
  },
  methods: {
    getRearName() {
      GET_REAL_NAME({
        type: 1
      }).then(res => {
        if (res.data == '审核中' || res.data == '审核失败' || res.data == '未认证') {
          this.$router.push('/mine/autonym')
        } else {
          GET_REAL_NAME({
            type: 2
          }).then(res => {
            this.account = res.data
            this.show = true
          })
        }
      });
    },
    deposit() {
      let that = this
      this.$confirm({
        title: '是否提现?',
        onOk() {
          if (that.money == null || that.money < 0) {
            that.$message.error('请输入正确的金额！')
          } else {
            CASH_MONEY({
              price: that.money
            }).then(res => {
              that.$message.success(res.msg)
              GET_REAL_NAME({
                type: 2
              }).then(res => {
                that.account = res.data
                that.show = true
              })
            })
          }
        },
        onCancel() {}
      });
    },
    handleSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          if (values.price <= 0) {
            this.$message.info('最小提现金额1元')
          } else {
            CASH_MONEY({
              price: values.price
            }).then(res => {
              this.$message.success(res.msg)
              GET_REAL_NAME({
                type: 2
              }).then(res => {
                this.account = res.data
                this.show = true
              })
            })
          }
        }
      });
    },
  }
};
</script>
<style lang="less" scoped>
.container {
  // border: 3px solid #0084ff;
  // border-radius: 6px;
  padding: 0 236px;
}
.wrap {
  border: 3px solid #0084ff;
  border-radius: 6px;
  padding: 10px;
  min-height: 562px;
  .w-title {
    height: 40px;
    line-height: 40px;
    background: #0084ff;
    color: #fff;
    margin-bottom: 20px;
    border-radius: 6px;
    font-size: 18px;
    font-weight: bold;
    padding-left: 16px;
  }
  .content{
    width: 300px;
    margin: 0 auto;
    .item {
      font-size: 14px;
      // font-weight: bold;
      color: rgba(0, 0, 0, 0.85);
      margin-bottom: 20px;
      display: flex;
      align-items: center;
    }
    .desc {
      color: #999;
      font-size: 14px;
      line-height: normal;
    }
  }
}
</style>